# callbacks.py
from langchain_core.callbacks import AsyncCallbackHandler
from langchain_core.messages import AIMessage

class FixNullContentHandler(AsyncCallbackHandler):
    async def on_llm_end(self, outputs, *, run_id, parent_run_id, tags=None, metadata=None, **kwargs):
        for gen_list in outputs.generations:
            for gen in gen_list:
                msg = getattr(gen, "message", None)
                if isinstance(msg, AIMessage) and msg.content is None and msg.tool_calls:
                    msg.content = ""
